<template>
  <div>
    <br>
    <el-switch v-model="SwitchValue" active-color="#13ce66" inactive-color="#ff4949"
               active-text="打开验证" inactive-text="关闭验证"
               style="margin-left:750px">
    </el-switch>
    <br>
    <br>
    <div style="box-shadow: 0 2px 4px rgba(0, 0, 0, .12), 0 0 6px rgba(0, 0, 0, .04); width:800px;margin-left:100px;">
      <br>
      <el-table
          :data="sequences"
          :row-class-name="rowClassName"
          :stripe="true"
          style="width: 100%"
          align="center">
        <el-table-column label="序号" width="100" align="center">
          <template slot-scope="scope">
            {{ scope.row.xh }}
          </template>
        </el-table-column>
        <el-table-column prop="sequence" label="算式" width="180" align="center"></el-table-column>

        <el-table-column label="答案" width="180" align="center">
          <template slot-scope="scope">
            <!--拿到行号-->
            <!--{{ scope.row.xh }}-->
            <el-input v-model="inputAns[scope.row.xh-1]" placeholder="请输入答案"></el-input>
            <!--<div>{{inputAns[scope.row.xh-1]}}</div>-->
          </template>
        </el-table-column>
        <el-table-column label="判断" width="100" align="center">
          <template slot-scope="scope">
            <!--<div>{{scope.row.answer}}</div>-->
            <div v-if="SwitchValue===true">
              <i class="el-icon-check" v-if="scope.row.answer == inputAns[scope.row.xh-1]"
                 style="font-size: 25px; color: #0fe10f"></i>
              <i class="el-icon-close"
                 v-else-if="scope.row.answer != inputAns[scope.row.xh-1] && inputAns[scope.row.xh-1]!= null"
                 style="font-size: 25px; color: red"></i>
              <i class="el-icon-edit" v-else style="font-size: 25px; color: skyblue"></i>
            </div>
          </template>
        </el-table-column>
      </el-table>
      <br>
      <el-button type="primary" round style="margin-left:350px" @click="refresh">再做一遍</el-button>
      <el-button type="primary" round style="margin-left:130px" @click="next"> <i class="el-icon-arrow-right"></i>进入下一项测试</el-button>
      <br>
      <br>
    </div>
  </div>
</template>
<script>
import axios from "axios";

export default {
  name: "CommonBody",
  created() {

  },
  mounted() {
    axios.get('http://localhost:8090/getSubtraction').then(response => (this.sequences = response.data));
  },
  data() {
    return {
      sequences: [],
      inputAns: [],
      SwitchValue: true,
    }
  },
  methods: {
    // 计算每一行的数据
    rowClassName({row, rowIndex}) {
      row.xh = rowIndex + 1;
    },
    //点击刷新页面
    refresh(){
      window.location.reload();
    },
    //跳转下一个
    next(){
      this.$router.push({path:'/MultiplicationBody'})
    }
  }
}
</script>
